package taweb.flex.air.fexBrowser.tree
{
	import mx.collections.*;
	import mx.controls.Alert;
	import mx.controls.treeClasses.*;
	import mx.controls.treeClasses.TreeItemRenderer;
	
	import taweb.flex.air.fexBrowser.struct.URLNode;

	public class CustomTreeItemRenderer extends TreeItemRenderer
	{
		public function CustomTreeItemRenderer() 
		{
			super();
			mouseEnabled = false;			
		}
		
		override public function set data(value:Object):void
		{
			if(value != null)
			{ 
				super.data = value;
				var valNode:TreeItem = value as TreeItem;
				var valLink:TreeLeaf = value as TreeLeaf;
				if(TreeListData(super.listData).depth == 2 && valNode!=null)
				{
					setStyle("color", valNode.color);
					setStyle("fontWeight", 'bold');
				}
				else if (valLink !=null)
				{
					setStyle("color", valLink.color);
					setStyle("fontWeight", 'normal');
				}else{
					setStyle("color", 0x00000);
					setStyle("fontWeight", 'normal');
				}
			}
		}	 
		
		override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
		{
			super.updateDisplayList(unscaledWidth, unscaledHeight);
			if(super.data)
			{
				if(TreeListData(super.listData).hasChildren)
				{
					var tmp:XMLList = new XMLList(TreeListData(super.listData).item);
					var myStr:int = tmp[0].children().length();
					super.label.text =  TreeListData(super.listData).label + "(" + myStr + " objects)";
				}
			}
		}
	}

}